package com.oa.service.impl;

import com.oa.dao.BaseDao;
import com.oa.dao.PersonnelDao;
import com.oa.entities.User;
import com.oa.entities.flows.Apps;
import com.oa.entities.flows.Flow;
import com.oa.entities.flows.Personnel;
import com.oa.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PersonnelServiceImpl extends UndeleteServiceImpl<Long,Personnel> implements PersonnelService {

    @Autowired
    private PersonnelDao dao;

    @Autowired
    private FlowService flowService;

    @Autowired
    private UserService userService;


    @Override
    protected BaseDao<Long, Personnel> getSelfDao() {
        return dao;
    }

    @Override
    public void setClass(Class<Personnel> clazz) {

    }

    @Override
    public void save(Apps apps, Long typeId,int num,Long userId) {
        Personnel personnel= new Personnel();
        Flow flow= flowService.find(typeId,num);
        personnel.setApprovaldate(System.currentTimeMillis());
        personnel.setApps(apps);
        personnel.setAppsId(apps.getId());
        personnel.setAuditType(flow.getAuditType());
        personnel.setDateType(flow.getDateType());
        personnel.setDesignationdate(System.currentTimeMillis());
        personnel.setFlow(flow);
        personnel.setFlowdate(System.currentTimeMillis());
        personnel.setLnstructions(null);
        personnel.setName(apps.getName());
        User user= null;
        if (userId==null){
            user= userService.getCurrent();
        }else {
            user= userService.get(userId);
        }
        personnel.setUser(user);
        personnel.setUserId(user.getId());
        personnel.setFlowId(flow.getId());
        save(personnel);
    }
}
